<%@page contentType="text"%>
<%@page import="bridge.*"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.Date"%>
<% 
	byte sensorID = Byte.parseByte(request.getParameter("sensorid"));
	
	Calendar start = Calendar.getInstance();
	
	int start_time = Integer.parseInt(request.getParameter("starttime"));
	int start_day = Integer.parseInt(request.getParameter("startday"));
	int start_month = Integer.parseInt(request.getParameter("startmonth"));
	int start_year = Integer.parseInt(request.getParameter("startyear"));
	
	start.set(Calendar.MINUTE, start_time % 100);
	start.set(Calendar.HOUR_OF_DAY, start_time / 100);
	start.set(Calendar.DAY_OF_MONTH, start_day);
	start.set(Calendar.MONTH, start_month - 1);
	start.set(Calendar.YEAR, start_year);
	start.set(Calendar.SECOND, 0);
	start.set(Calendar.MILLISECOND, 0);
	
	
	
	Calendar end = Calendar.getInstance();
	
	int end_time = Integer.parseInt(request.getParameter("endtime"));
	int end_day = Integer.parseInt(request.getParameter("endday"));
	int end_month = Integer.parseInt(request.getParameter("endmonth"));
	int end_year = Integer.parseInt(request.getParameter("endyear"));
	
	end.set(Calendar.MINUTE, end_time % 100);
	end.set(Calendar.HOUR_OF_DAY, end_time / 100);
	end.set(Calendar.DAY_OF_MONTH, end_day);
	end.set(Calendar.MONTH, end_month - 1);
	end.set(Calendar.YEAR, end_year);
	end.set(Calendar.SECOND, 0);
	end.set(Calendar.MILLISECOND, 0);
	
	out.println(start.getTime() + " to " + end.getTime() + ",");
	
	DatabaseAccessor dba = DatabaseAccessor.getInstance(); 
	
	ArrayList<Pair<Long,Float>> pairs = null;
	SensorType type = null;
	double min = 0.0;
	double max = 1.0;
	if(dba != null)
	{
		pairs = dba.getRawData(sensorID, start.getTime().getTime(), end.getTime().getTime());
		type = dba.getSensor(sensorID).type;
		min = type.min;
		max = type.max;
	}
%>

<%
if(pairs != null)
%>
	<%="Date(ms), Value(" + type.unit + "),\n"%>
	<%for(int k = 0; k < pairs.size(); k++)
	{
	%>
		<%= pairs.get(k).fst + ", " + (pairs.get(k).snd * (max - min) + min)+ '\n'%>
	<%
	}
%>
